/*
 * @Author: Jiraiya
 * @Date: 2020-02-28 22:55:35
 * @LastEditors: Jiraiya
 * @LastEditTime: 2020-02-28 23:04:19
 * @Description: 
 */

//🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏

const [a, ...b] = [1, 2, 3, 4]
// a = 1 b = [2, 3, 4]

const [c, d, e] = ['a']
// c = 'a' d = undefined e = []

let [x, y, z] = new Set(['a', 'b', 'c'])
// x = 'a' y = 'b' z = 'c'

const [m, n] = '123'
//m = 1 n = 2

function* f() {
    yield 1;
    yield 2;
    return 3;
}

const [o, p, r] = f()
// o = 1 p = 2 r = undefined

//🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏

let obj = {
    p: [
        'Hello',
        {
            y: 'World'
        }
    ]
};

let {
    p,
    p: [x, {
        y
    }]
} = obj;
x // "Hello"
y // "World"
p // ["Hello", {y: "World"}]


let obj = {};
let arr = [];

({ foo: obj.prop, bar: arr[0] } = { foo: 123, bar: true });

obj // {prop:123}
arr // [true]

//🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏

const {a = 1, b = 2} = {a: undefined, b: null}
// a = 1 b = null

//🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏

let {length: len} = '123'
// len = 3

let {toString: str} = 123
// str = '123'

function  f([x, y]){
    return {x, y}
}
const {x, y} = f([1, 2])
// x = 1 y = 2

const map = new Map()
map.set('a', 1)
map.set('b', 2)
for(let [key, val] of map){

}